Current Location: Home> Function Categories> date_create

date_create

DateTime::__construct alias - Returns a new DateTime object
Name:date_create
Category:Date and time
Programming Language:php
One-line Description:Returns the new DateTime object.

Definition and usage

The date_create() function returns a new DateTime object.

Example

Example 1

Return a new DateTime object and format the date:

 <?php
$date = date_create ( "2016-09-25" ) ;
echo date_format ( $date , "Y/m/d" ) ;
?>

Try it yourself

Example 2

Returns a new DateTime object with the given time zone and formats the date and time:

 <?php
$date = date_create ( "2013-03-15 23:40:00" , timezone_open ( "Europe/Oslo" ) ) ;
echo date_format ( $date , "Y/m/d H:iP" ) ;
?>

Try it yourself

grammar

 date_create ( time , timezone ) ;
parameter describe
time Optional. Specify date/time string. NULL Indicates the current date/time.
timezone

Optional. Specifies the time zone. The default is the current time zone.

Tip: View a list of all time zones supported in PHP .

Similar Functions
Popular Articles